<!--tvm票款差异协查-->
<template>
  <div class="JieZhangDanAndSCCengji el-card is-always-shadow el-card__body">
    <avue-crud
      ref="crud"
      :option="option"
      :table-loading="listLoading"
      :data="data"
      :page.sync="page"
      :search.sync="searchForm"
      @search-change="handleFilter"
      @selection-change="selectionChange"
      @refresh-change="refreshChange"
      @on-load="refreshChange"
      :row-style="rowStyle"
      :cell-style="cellStyle">
      <template slot="menuRight">
<!--        <el-button type="primary"  size="mini" @click="replaceContent()">一键替换</el-button>-->
        <el-button type="primary"  size="mini" @click="sendStatus">下发</el-button>
        <el-button type="primary"  size="mini" @click="exportData">导出</el-button>
      </template>
      <template slot-scope="scope" slot="lineCodeSearch">
        <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" clearable filterable>
          <el-option
            v-for="(item,index) in lineCodes"
            :key="index"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </template>
      <template slot-scope="scope" slot="stationCodeSearch">
        <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" filterable clearable @change="changeStation">
          <el-option
            v-for="(item,index) in stationCodes"
            :key="index"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </template>
      <template slot-scope="scope" slot="conductorPersonCodeSearch">
        <el-select v-model="searchForm.conductorPersonCode" placeholder="请选择" style="width: 150px" filterable clearable>
          <el-option
            v-for="(item,index) in conductorPersonNames"
            :key="index"
            :label="item.nikename"
            :value="item.userCode">
          </el-option>
        </el-select>
      </template>
      <template slot-scope="scope" slot="equipmentNumberSearch">
        <el-select v-model="searchForm.equipmentNumber" placeholder="请选择" style="width: 150px" clearable>
          <el-option
            v-for="(item,index) in equipmentNumbers"
            :key="index"
            :label="item.operationCode"
            :value="item.operationCode">
          </el-option>
        </el-select>
      </template>
      <template slot="searchMenu" slot-scope="{row,size}">
        <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm);getList()}" icon="el-icon-delete">清空</el-button>
      </template>
      <template slot-scope="scope" slot="menu">
<!--        <el-button type="text" v-if="scope.row.assistStatus!='3'" size="small" plain @click.stop="previewEditor(scope.row,scope.row.assistStatus)">预览</el-button>-->
        <el-button type="text" v-if="scope.row.assistState=='3'" size="small" plain @click.stop="previewEditor(scope.row)">回馈预览</el-button>
      </template>
    </avue-crud>
    <HuikuiInfo ref="HuikuiInfo" v-if="isShowDia"></HuikuiInfo>
</div>
</template>


<script>
    import {getForm, postForm} from '@/api/gen/gen'
    import moment from "moment";
    import HuikuiInfo from './../shouPiaoYuanCJDXY/shoupiaoyuanCJCYDXC/HuikuiInfo'
    import {
      clearSelect,
      fenExYuangettoFixed,
      getgetStationCodes,
      getLineCodes, getLineName, getMappingStatus, getStationName, getSwPmDeviceOperationCodeList, getSysUserToLS,
      getXieChaStatusFormat, setSearchFiledsEmpty,
      xieChaStatus
    } from "../../../../api/subwayRat/commonCheck";
    import {exportDataToExcel} from "../../../../api/subwayRat/exportSelf";
    import {getSwAuConductorHierarchyAmountDifferenceList} from "../../../../api/subwayRat/conductorDifferences/conductorTicketChaYiShenhe/shouPiaoYuanCJCY";
    import {getPersonRole} from "../../../../api/subwayRat/reportMondify/reportMistakeInfo";
    import {addAssistSwAuConductorHierarchyAmountDifference} from "../../../../api/subwayRat/conductorDifferences/conductorTicketChaYiShenhe/shouPiaoYuanCJDXY/shoupiaoyuanCJCYDXC/LCAndACCCengJiCYDXC";
    export default {
      components:{
        HuikuiInfo
      },
      data() {
            return {
              isShowDia:false,
              listLoading: true,
              lineCodes:[],
              stationCodes:[],
              conductorPersonNames:[],
              equipmentNumbers:[],
              selectKeys:[], //存放对像
              selectKeyVals:[], //存放值
              data: [],
              searchForm:{
                lineCode:'9',
                stationCode:''
              },
              page: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 20, // 每页显示多少条,
                isAsc: false// 是否倒序
              },
              option:{ },
            }
        },
        created() {
          this.changeLine("9")
        this.getOption();
        },
        methods: {
          refreshChange() {
            this.getList()
          },
          cellStyle({ row, column, rowIndex,columnIndex }) {
            if(14==columnIndex ){
              if (row.diffSelltkAmount < 0 ) {
                return {
                  color: "red",
                };
              }else if (row.diffSelltkAmount > 0 ) {
                return {
                  color: "#bed742",
                };
              }
            }
            if(15==columnIndex){
              if (row.diffInvestAmount < 0 ) {
                return {
                  color: "red",
                };
              }else if (row.diffInvestAmount > 0) {
                return {
                  color: "#bed742",
                };
              }
            }
            if(16==columnIndex){
              if (row.diffFaretkAmount < 0 ) {
                return {
                  color: "red",
                };
              }else if (row.diffFaretkAmount > 0) {
                return {
                  color: "#bed742",
                };
              }
            }
          },
          rowStyle({ row, column, rowIndex }) {
            // if (row.diffInvestAmount != 0 || row.diffSelltkAmount != 0 || row.diffFaretkAmount != 0) {
            //   return {
            //       backgroundColor: "#eee",
            //       color: "red",
            //   };
            // }
          },
          setSearchFiledsEmpty,
          getList() {
            this.listLoading = true;
            Object.assign(this.searchForm,this.page);
            let param={compareType:4};
            Object.assign(param,this.searchForm);
            param.comparativeType=2;
            getSwAuConductorHierarchyAmountDifferenceList(param).then((response)=>{
              this.data = response.data.data;
              this.listLoading = false;
              this.page.total=response.data.total;
            });
          },
          selectionChange(list){
            this.selectKeys=list;
            this.selectKeyVals=[];
            for(let i=0;i<list.length;i++){
              this.selectKeyVals.push(list[i].id);
            }
          },
          handleFilter(params, done) {
            Object.assign(this.searchForm,params);
            this.getList()
            done()
          },
          // replaceContent(){
          //   if(this.selectKeys.length<=0 || this.isassistInvestStatus()){
          //     this.$message.info("请选择已协查数据操作！");
          //     return;
          //   }
          //
          //   let ids=[];
          //   for(let i=0;i<this.selectKeys.length;i++){
          //     if(this.selectKeys[i].replaceStatus==0){
          //       ids.push(this.selectKeys[i].id);
          //     }
          //   }
          //   if(ids.length==0){
          //     this.$message.warning("无有效替换数据！");
          //     return;
          //   }
          //   replaceSwAuItvmOnlineAmountHierarchyDifference({ids:ids.join(",")}).then(res=>{
          //     if(res.data.code==0){
          //       this.$message.success("操作成功！");
          //       this.getList();
          //       clearSelect(this.$refs.JieZhangDanAndSCCengji)
          //     }else{
          //       this.$message.error(res.data.msg);
          //     }
          //   })
          // },
          previewEditor(row){ //回馈预览
            this.isShowDia=true;
            this.$nextTick(()=>{
              this.$refs.HuikuiInfo.recallShow(row);
            })
          },
          replaceContentOne(row){ //一件替换
            this.isShowDia=true;
            this.$nextTick(()=>{
              this.$refs.HuikuiInfo.recallShow(row.id,[row],1);
            })
          },
          sendStatus(){
            if(this.selectKeys.length<=0){
              this.$message.warning("请选择要设置的数据！");
              return;
            }
            for(let i=0;i<this.selectKeys.length;i++){
              if(this.selectKeys[i].isAddAssist==1){
                this.$message.warning("请选择未加入协查的数据！");
                return;
              }
            }
            addAssistSwAuConductorHierarchyAmountDifference({ids:this.selectKeyVals.join(",")}).then(res=>{
              if(res.data.code==0){
                this.$message.success("操作成功！");
                this.getList();
              }else{
                this.$message.error("操作失败！");
              }
            })
          },
          changeLine(v){ //改变线路时
            getgetStationCodes(v).then(res=>{
              this.stationCodes=res;
              this.searchForm.stationCode='';
            })
          },
          changeStation(v){
            getSysUserToLS({lineCode:this.searchForm.lineCode, stationCode:v}).then((res)=>{
              this.conductorPersonNames=res.data.data;
            });
            this.getSheBei();
          },
          getSheBei(){
            getSwPmDeviceOperationCodeList({lineCode:this.searchForm.lineCode,stationCode:this.searchForm.stationCode}).then(r=>{
              this.equipmentNumbers=r.data.data;
            });
          },
          isassistInvestStatus(){ // 是否协查
            for(let i=0;i<this.selectKeys.length;i++){
              let row=this.selectKeys[i];
              if(row.assistStatus==3){
                return false
              }
            }
            return true;
          },
          async exportData(){ // 导出
            this.searchForm.pageNo=1;
            this.searchForm.pageSize=1000000000;
            if(this.selectKeys.length>0){
                let newData = JSON.parse(JSON.stringify(this.selectKeys));
                exportDataToExcel(newData,this.option.column,'ACC层级差异待协查');
            }else {
              let res=await getSwAuConductorHierarchyAmountDifferenceList(this.searchForm);
              let data = res.data.data;
              exportDataToExcel(data,this.option.column,'ACC层级差异待协查');
            }
          },
          getOption(){
            let th=this;
            this.option={
              emptyBtn:false,
              editBtn:false,
              delBtn:false,
              addBtn:false,
              border: true,
              index:true,
              indexLabel:'序号',
              page:true,
              align:'center',
              menuWidth:150,
              menuAlign:'center',
              selection: true,
              reserveSelection:true,
              height: 500,
              column:[{label:"线路",width: 100,hide:true,
                "prop":"lineCode",type:'select',search:false,searchslot:true,formatter: function(row, value , label, column){
              return getLineName(value);
            }},
                {label:"站点",width: 180,
                  "prop":"stationCode",type:'select',search:true,searchslot:true,formatter: function(row, value , label, column){
              return getStationName(row.lineCode,value);
            }},
                {label:"售票员名称",width: 120,
                  "prop":"conductorPersonName",formatter:function (row,value , label, column) {
                    return row.conductorPersonName;
                  }},
                {label:"售票员",
                  "prop":"conductorPersonCode",search:true,searchslot:true,formatter:function (row,value , label, column) {
                    return row.conductorPersonCode;
                  }},
                {label:"设备操作号",width: 120,
                  "prop":"equipmentNumber",type:'select',search:true,searchLabelWidth:100,searchslot:true},
                {label:"收入日期",width: 120,
                  "prop":"settleTime",type:'date',format:'yyyy-MM-dd',valueFormat:'yyyy-MM-dd',search:true},
                {label:"LC售票金额",width: 120,
                  "prop":"sellAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'sellAmount');
                  }},
                {label:"LC充值金额",width: 120,
                  "prop":"investAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'investAmount');
                  }},
                {label:"LC补票金额",width: 120,
                  "prop":"faretkAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'faretkAmount');
                  }},
                {label:"ACC售票金额", width: 120,"prop":"comparativeSelltkAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'comparativeSelltkAmount');
                  }},
                {label:"ACC充值金额", width: 120,"prop":"comparativeInvestAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'comparativeInvestAmount');
                  }},
                {label:"ACC补票金额", width: 120,"prop":"comparativeFaretkAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'comparativeFaretkAmount');
                  }},
                 {label:"售票差异金额",width: 120, "prop":"diffSelltkAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'diffSelltkAmount');
                }},
                {label:"充值差异金额",width: 120, "prop":"diffInvestAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'diffInvestAmount');
                }},
                {label:"补票差异金额",width: 120, "prop":"diffFaretkAmount",formatter:function (row,value , label, column) {
                    return fenExYuangettoFixed(row,'diffFaretkAmount');
                }},
                // {label:"充值差异金额", "prop":"chongzhichayi",hide:true,formatter:function(row, value , label, column){
                //     let chaYi = th.getChaYi(row,'investAmount','comparativeInvestAmount');
                //     row.chongzhichayi=chaYi;
                //     return fenExYuangettoFixed(row,'chongzhichayi');
                //   }},
                // {label:"售票差异金额", "prop":"shoumaichayi",hide:true,formatter:function(row, value , label, column){
                //     let chaYi = th.getChaYi(row,'sellAmount','comparativeSelltkAmount');
                //     row.shoumaichayi=chaYi;
                //     return fenExYuangettoFixed(row,'shoumaichayi');
                //   }},
                // {label:"补票差异金额", "prop":"guzhangtuikuanchayi",hide:true,formatter:function(row, value , label, column){
                //     let chaYi = th.getChaYi(row,'faretkAmount','comparativeFaretkAmount');
                //     row.guzhangtuikuanchayi=chaYi;
                //     return fenExYuangettoFixed(row,'guzhangtuikuanchayi');
                //   }},
                {label:"是否加入协查",width: 120,
                  "prop":"isAddAssist",formatter:function (row,v){
                  return getMappingStatus('spy_is_add_assist',v);
                  }},
                {label:"协查状态",
                  "prop":"assistState",type:'select',
                  formatter:function(row, value , label, column){
                    return getXieChaStatusFormat(value);
                  }},
                {prop:'sendPersonName',width:120,label:'下发人',}
              ]
            }
          },
          getChaYi(row,compareFirst,compareSec){ //结账金额 sc 差额
            if(!row[compareFirst] || !row[compareSec]){
              return '';
            }
            return Number(row[compareFirst])-Number(row[compareSec]);
          }
        },
      mounted() {
        getLineCodes().then(res=>{ //获取线路
          this.lineCodes=res;
        });
        if(this.$route.query.conductorTicketChaYiShenhe){
          Object.assign(this.searchForm,this.$route.query.conductorTicketChaYiShenhe);
          this.getList();
        }
      }
    }
</script>
<style lang="scss">

</style>
